package com.fz.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by webrx on 2018-06-27.
 */
@Controller @RequestMapping("/admin")
public class AdminController {
    @RequestMapping
    public String index(){
        return "/admin/index";
    }
    @RequestMapping("/login")
    public void login(){}

    @RequestMapping("/check")
    public String check(String account,String passwd,HttpServletRequest req){
        String url = "";
        if("admin".equalsIgnoreCase(account) && "123".equals(passwd)){
            req.getSession().setAttribute("admin",account);
            url = "redirect:/admin/";
        }else{
            url = "redirect:/admin/login";
        }
        return url;
    }

    @RequestMapping("/logout")
    public String logout(HttpServletRequest req){
        //req.getSession().invalidate();
        req.getSession().removeAttribute("admin");
        return "redirect:/";
    }
}
